fix(review): close the contributor open-PR cap's ordering + TOCTOU race#7695
Merged
Conversation
On 2026-07-21 a burst of 6 PRs from one contributor against a cap of 2 exposed two bugs in the per-contributor open-item cap: only 2 of the 4 excess PRs were caught, and PRs merged that should have been closed. Ordering: the cap check only ran as the LAST step of the full review pipeline (miner detection, AI slop advisory, linked-issue satisfaction, the full AI code review, CI-completeness verification, public surface publish), so an over-cap PR paid for that entire pipeline before being caught. Confirmed live: the contributor_cap_ci_cancelled event for the burst logged "cancelled 0 of 0 in-flight workflow runs" -- CI had already finished by the time the close fired. Adds a cheap, CI-independent short-circuit on PR-open that closes an over-cap PR before any of that work runs, while the existing end-of-pipeline check stays as defense-in-depth for state that changes mid- pipeline. A repo with no cap configured, an ignored/exempt author, or a lock-contended pass pays nothing extra -- byte-identical to today. Race: cap membership was recomputed independently by every sibling PR's own pipeline pass, using whichever "confirmed still open" siblings existed at that moment -- not one shared snapshot for the burst. A merge could therefore execute off a stale "under cap" conclusion after a sibling's later close made the author over cap. Adds a per-(repo, author) mutex (the existing atomic claim/release transient-lock primitive) around the cap decision, plus a re-check under that same mutex immediately before a merge actually executes -- redirecting to a "denied" outcome instead of merging when a fresh check confirms the author is now over cap, so the next natural re-evaluation plans a close off accurate state.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7695 +/- ##
==========================================
- Coverage 88.52% 88.52% -0.01%
==========================================
Files 725 725
Lines 76052 76111 +59
Branches 22640 22658 +18
==========================================
+ Hits 67326 67374 +48
- Misses 7681 7688 +7
- Partials 1045 1049 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On 2026-07-21 a burst of 6 PRs from one contributor against a cap of 2 exposed two bugs in the per-contributor open-item cap (PRs #7284-#7289): only 2 of the 4 excess PRs were caught, and PRs merged that should have been closed.
Ordering (resource waste): the cap check only ran as the LAST step of the full review pipeline (miner detection, AI slop advisory, linked-issue satisfaction, the full AI code review, CI-completeness verification, public surface publish), so an over-cap PR paid for that entire pipeline before being caught. Confirmed via the real audit log:
contributor_cap_ci_cancelledfor the burst logged "cancelled 0 of 0 in-flight workflow run(s)" — CI had already finished by the time the close fired. Adds a cheap, CI-independent short-circuit onpull_requestopenedthat closes an over-cap PR before any of that work runs. The existing end-of-pipeline check stays in place as defense-in-depth for state that changes mid-pipeline. A repo with no cap configured, an ignored/exempt author, or a lock-contended pass pays nothing extra — byte-identical to today.Race (TOCTOU): cap membership was recomputed independently by every sibling PR's own pipeline pass, using whichever "confirmed still open" siblings existed at that exact moment — not one shared snapshot for the burst. A merge could therefore execute off a stale "under cap" conclusion after a sibling's later close made the author over cap. Adds a per-
(repo, author)mutex (the existing atomic claim/release transient-lock primitive already used for the per-PR actuation lock) around the cap decision, plus a re-check under that same mutex immediately before a merge actually executes — redirecting to a "denied" outcome instead of merging when a fresh check confirms the author is now over cap, so the next natural re-evaluation plans a close off accurate state.prReadyForReview's own CI-wait/staleness-cap/dirty-base internals are completely untouched by either fix.Test plan
queue,queue-2/3/4,agent-actions,agent-action-executor,ci-completion-fork-resume,pr-panel-retrigger-pending-force-review) — 1010/1010 passingnpm run test:coverage(full, unsharded) — all green, no regressionsDA/BRDAagainst the diff hunks); remaining pre-existing/defensive branch arms carry justifiedv8 ignorecomments mirroring this file's own established conventionnpx tsc --noEmitcleannpm audit --audit-level=moderateclean